#!/bin/sh

set -eu

INSTALL_DIR="$JIAPKG_INSTALL_DIR"
JOBS="$JIAPKG_JOBS"
JIAPKG="$JIAPKG_EXE"

jiapkg_build() {
	cmake -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
		-Dprotobuf_ABSL_PROVIDER=package \
		-DCMAKE_PREFIX_PATH="$($JIAPKG info --install-dir abseil_cpp)" \
		-Dprotobuf_BUILD_TESTS=OFF \
		-DCMAKE_BUILD_TYPE=Release -Bbuild
	cmake --build build -j"$JOBS"
}

jiapkg_install() {
	cmake --install build --strip
}

case "$1" in
build) jiapkg_build ;;
install) jiapkg_install ;;
esac
